package com.wjp.banquet.service.impl;

import com.wjp.banquet.common.util.ParamCheckUtil;
import com.wjp.banquet.common.util.UserUtil;
import com.wjp.banquet.dto.UserLoginDTO;
import com.wjp.banquet.entity.User;
import com.wjp.banquet.mapper.UserMapper;
import com.wjp.banquet.service.UserService;
import com.wjp.banquet.vo.UserLoginResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;

/**
 * @Author 王君平
 * @Date 2024/4/26 11:56
 * @Description
 */
@Service
public class UserServiceImpl implements UserService {



    @Autowired
    private UserMapper userMapper;
    @Override
    public void login(UserLoginDTO dto, HttpSession session) {
        User user = userMapper.getByUsername(dto.getUsername());
        ParamCheckUtil.objectNull(user,"用户不存在");

        ParamCheckUtil.notTrue(user.getPassword().equals(dto.getPassword()),"用户名或密码错误");

        User userInfo = new User();
        userInfo.setId(user.getId());
        session.setAttribute(UserUtil.USER_INFO, userInfo);

        return;

    }

    @Override
    public void logout(HttpSession session) {
        session.removeAttribute(UserUtil.USER_INFO);
    }
}
